<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!doctype html>
<html lang="zh-CN">
<head>
<meta charset="utf-8">
<meta author="tianjindong.cn 田金东">
<meta name="renderer" content="webkit">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>听到微笑的博客文章页面</title>
<link rel="stylesheet" type="text/css" href="/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="/css/nprogress.css">
<link rel="stylesheet" type="text/css" href="/css/style.css">
<link rel="stylesheet" type="text/css" href="/css/font-awesome.min.css">
<link rel="apple-touch-icon-precomposed" href="/images/icon/icon.png">
<link rel="stylesheet" type="text/css" href="/css/fileinput.min.css">
<link rel="shortcut icon" href="/images/icon/favicon.ico">
<script src="/js/jquery-2.1.4.min.js"></script>
<script src="/js/nprogress.js"></script>
<script src="/js/jquery.lazyload.min.js"></script>
</head>

<body class="user-select single">
	<jsp:include page="common/top.jsp" />
	<!-- 修改个人信息的模态框（Modal） -->
	<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
					<h4 class="modal-title" id="myModalLabel">修改个人信息</h4>
				</div>
				<div class="modal-body">
					<div class="row">
						<div class="col-md-1 col-xs-0"></div>
						<div class="col-md-10 col-xs-12">
							<form id="updateUserInfo" class="form-horizontal">
								<input id="imgurl" type="hidden" name="imgurl">
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">头像</label>
									<div class="col-sm-10">
										<c:choose>
											<c:when test="${user.imgurl==null || user.imgurl=='' }">
												<img id="headImg" class="infoHeadImg" src="${pageContext.request.contextPath }/images/icon/icon.png" alt="" />
											</c:when>
											<c:otherwise>
												<img id="headImg" class="infoHeadImg" src="${user.imgurl }" alt="" />
											</c:otherwise>
										</c:choose>
										<input id="fileinput" type="file" class="form-control file" name="uploadFile" multiple>
									</div>
								</div>
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">昵称</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="name" id="inputEmail3" value="${user.name }" placeholder="请输入您的昵称">
									</div>
								</div>
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">性别</label>
									<div class="col-sm-10">
										<c:choose>
											<c:when test="${user.sex==1 }">
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio1" value="1" checked="checked">
													男
												</label>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio2" value="2">
													女
												</label>
											</c:when>
											<c:when test="${user.sex==2 }">
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio1" value="1">
													男
												</label>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio2" value="2" checked="checked">
													女
												</label>
											</c:when>
											<c:otherwise>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio1" value="1">
													男
												</label>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio2" value="2">
													女
												</label>
											</c:otherwise>
										</c:choose>

									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2 control-label">生日</label>
									<div class="col-sm-10">
										<input type="date" class="form-control" name="birthday" id="inputPassword3" value="${user.birthdayString }">
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2 control-label">地区</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="area" id="inputPassword3" value="${user.area }" placeholder="您所在的地区">
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2 control-label">行业</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" name="vocation" id="inputPassword3" value="${user.vocation }" placeholder="您所在的行业">
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2  control-label">简介</label>
									<div class="col-sm-10">
										<textarea style="resize:none" class="form-control" name="info" id="inputPassword3" rows="6" placeholder="请输入个人简介">${user.info }</textarea>
									</div>
								</div>
							</form>
						</div>
						<div class="col-md-1 col-xs-0"></div>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-primary" onclick="submitForm()">保存</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal -->
	</div>
	<section class="container">
		<div class="content-wrap">
			<div class="panel panel-default">
				<div class="panel-heading">个人信息</div>
				<div class="panel-body">
					<div class="row">
						<div class="col-md-3 col-xs-1"></div>
						<div class="col-md-6 col-xs-10">
							<form class="form-horizontal">
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label hidden-xs" style="margin-top: 7px">头像</label>
									<div class="col-sm-10">
										<c:choose>
											<c:when test="${user.imgurl==null || user.imgurl==''}">
												<img id="headImg" class="infoHeadImg" src="${pageContext.request.contextPath }/images/icon/icon.png" alt="" />
											</c:when>
											<c:otherwise>
												<img id="headImg" class="infoHeadImg" src="${user.imgurl }" alt="" />
											</c:otherwise>
										</c:choose>
										<!-- 按钮触发模态框 -->
										<a class=" btn-lg" data-toggle="modal" style="float: right;font-weight: 500;font-size: small;color: #757575;margin-top: 8px" data-target="#myModal">修改个人信息</a>
									</div>
								</div>
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">用户名</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="inputEmail3" value="${user.username }" readonly="readonly">
									</div>
								</div>
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">邮箱</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="inputEmail3" value="${user.email }" readonly="readonly">
									</div>
								</div>
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">昵称</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="inputEmail3" value="${user.name }" placeholder="请为您的账号取一个昵称吧" readonly="readonly">
									</div>
								</div>
								<div class="form-group">
									<label for="inputEmail3" class="col-sm-2 control-label">性别</label>
									<div class="col-sm-10">
										<c:choose>
											<c:when test="${user.sex==1 }">
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio1" value="1" checked="checked" disabled="disabled">
													男
												</label>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio2" value="2" disabled="disabled">
													女
												</label>
											</c:when>
											<c:when test="${user.sex==2 }">
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio1" value="1" disabled="disabled">
													男
												</label>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio2" value="2" checked="checked" disabled="disabled">
													女
												</label>
											</c:when>
											<c:otherwise>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio1" value="1" disabled="disabled">
													男
												</label>
												<label class="radio-inline">
													<input type="radio" name="sex" id="inlineRadio2" value="2" disabled="disabled">
													女
												</label>
											</c:otherwise>
										</c:choose>
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2 control-label">生日</label>
									<div class="col-sm-10">
										<input type="date" class="form-control" id="inputPassword3" readonly="readonly" value="${user.birthdayString }">
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2 control-label">地区</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="inputPassword3" placeholder="您所在的地区" value="${user.area }" readonly="readonly">
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2 control-label">行业</label>
									<div class="col-sm-10">
										<input type="text" class="form-control" id="inputPassword3" placeholder="您所在的行业" value="${user.vocation }" readonly="readonly">
									</div>
								</div>
								<div class="form-group">
									<label for="inputPassword3" class="col-sm-2  control-label">简介</label>
									<div class="col-sm-10">
										<textarea class="form-control" id="inputPassword3" rows="6" style="resize:none" placeholder="请输入个人简介" readonly="readonly">${user.info }</textarea>
									</div>
								</div>
							</form>
						</div>
						<div class="col-md-3 col-xs-1"></div>
					</div>
				</div>
			</div>
		</div>
	</section>
	<jsp:include page="common/footer.jsp" />
	<script src="/js/bootstrap.min.js"></script>
	<script src="/js/jquery.ias.js"></script>
	<script src="/js/scripts.js"></script>
	<script src="/js/jquery.qqFace.js"></script>
	<script src="/js/console.js"></script>
	<script src="/js/fileinput.min.js"></script>
	<script src="/js/zh.js"></script>
	<script type="text/javascript">
		function submitForm() {
			//表单信息
			var data = $("#updateUserInfo").serialize();
			$.post(
				"${pageContext.request.contextPath}/user/update.action",
				data,
				function(data) {
					window.location.reload();
				}
			);
	
		}
	
		$("#fileinput").fileinput({
			language : 'zh', //设置文中文
			uploadUrl : "/upload.action", // 文件上传路径
			showPreview : false, //是否显示预览框
			autoReplace : true, //重新选择时，自动替换当前文件
			uploadAync : true, //是否异步上传
			allowedFileExtensions : [ 'jpg', 'jpeg', 'png', 'gif' ], //允许上传的文件拓展名，数组，如果设置为png，那么jpg就不能上传
			minFileSize : 1, //上传文件的最小size，如果为0，则不限制
			maxFileSize : 5000, //上传文件的最大size
			minFileCount : 1, //最小文件上传数量
			maxFileCount : 1, //最大文件上传数量
		});
	
	
		//文件上传成功后
		$("#fileinput").on("fileuploaded", function(event, data, previewId, index) {
			//event当前事件，data则是数据，包括上传后服务器返回的数据+ 自身的一些数据
			//data.response才为服务器返回的数据，如果是data.filenames则为当前要上传的文件名(不包括上传的)
			//previewId 预览的下标，从0开始计算，注意并不是数字，而是一串字符串 + _index
			//index 下标，预览下标与index不一致，因为当你导入sortable.js可以排序就可能会不一致
			$("#imgurl").val(data.response.data[0]);
			$("#headImg").attr("src", data.response.data[0]);
			console.info(data.response.data[0]);
		});
	</script>
</body>
</html>